home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / wall / RCS / wall.c,v < prev    next >
Text File  |  1992-04-22  |  19KB  |  983 lines

  1. head     1.13;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.13
  10. date     92.04.22.14.21.28;  author kupfer;  state Exp;
  11. branches ;
  12. next     1.12;
  13.  
  14. 1.12
  15. date     90.04.30.13.38.18;  author douglis;  state Exp;
  16. branches ;
  17. next     1.11;
  18.  
  19. 1.11
  20. date     90.04.30.10.59.00;  author douglis;  state Exp;
  21. branches ;
  22. next     1.10;
  23.  
  24. 1.10
  25. date     89.12.11.13.09.32;  author douglis;  state Exp;
  26. branches ;
  27. next     1.9;
  28.  
  29. 1.9
  30. date     89.11.27.14.27.10;  author douglis;  state Exp;
  31. branches ;
  32. next     1.8;
  33.  
  34. 1.8
  35. date     89.11.21.15.56.21;  author douglis;  state Exp;
  36. branches ;
  37. next     1.7;
  38.  
  39. 1.7
  40. date     89.09.29.11.24.14;  author douglis;  state Exp;
  41. branches ;
  42. next     1.6;
  43.  
  44. 1.6
  45. date     89.09.29.11.22.18;  author douglis;  state Exp;
  46. branches ;
  47. next     1.5;
  48.  
  49. 1.5
  50. date     89.09.29.11.14.47;  author douglis;  state Exp;
  51. branches ;
  52. next     1.4;
  53.  
  54. 1.4
  55. date     89.08.28.15.32.58;  author douglis;  state Exp;
  56. branches ;
  57. next     1.3;
  58.  
  59. 1.3
  60. date     89.06.24.18.31.26;  author rab;  state Exp;
  61. branches ;
  62. next     1.2;
  63.  
  64. 1.2
  65. date     89.03.12.20.47.41;  author rab;  state Exp;
  66. branches ;
  67. next     1.1;
  68.  
  69. 1.1
  70. date     88.09.16.14.12.39;  author rab;  state Exp;
  71. branches ;
  72. next     ;
  73.  
  74.  
  75. desc
  76. @
  77. @
  78.  
  79.  
  80. 1.13
  81. log
  82. @Fix to understand new pdev naming scheme.  Based on code from dlong.
  83. @
  84. text
  85. @/* 
  86.  * wall.c --
  87.  *
  88.  * Write to all.  Sends a message to the /dev/syslog window of
  89.  * each machine, or the local host if specified.
  90.  *
  91.  * Copyright 1989 Regents of the University of California
  92.  * Permission to use, copy, modify, and distribute this
  93.  * software and its documentation for any purpose and without
  94.  * fee is hereby granted, provided that the above copyright
  95.  * notice appear in all copies.  The University of California
  96.  * makes no representations about the suitability of this
  97.  * software for any purpose.  It is provided "as is" without
  98.  * express or implied warranty.
  99.  */
  100.  
  101. #ifndef lint
  102. static char rcsid[] = "$Header: /sprite/src/cmds/wall/RCS/wall.c,v 1.12 90/04/30 13:38:18 douglis Exp Locker: kupfer $";
  103. #endif /* not lint */
  104.  
  105. #define NDEBUG
  106.  
  107. #include <sprite.h>
  108. #include <stdio.h>
  109. #include <stdlib.h>
  110. #include <fcntl.h>
  111. #include <mig.h>
  112. #include <host.h>
  113. #include <sys/time.h>
  114. #include <pwd.h>
  115. #include <option.h>
  116. #include <sys/signal.h>
  117. #include <sys/stat.h>
  118. #include <sys/wait.h>
  119. #include <errno.h>
  120. #include <rloginPseudoDev.h>
  121. #include <setjmp.h>
  122. #include <ulog.h>
  123.  
  124.  
  125. #define MAX_NUM_HOSTS   0x100
  126. #define MAX_MSG_LEN     0x400
  127. #define TIME_OUT        180
  128. #define HOST_NAME_SIZE  64
  129.  
  130. #ifdef __STDC__
  131. static void SendMsg(char *msg, int msize, char *host, int doRlogin);
  132. static void FillAlert(void);
  133. static void Down(int n);
  134. static void Prompt(void);
  135. #else
  136. static void SendMsg();
  137. static void FillAlert();
  138. static void Down();
  139. static void Prompt();
  140. #endif
  141.  
  142. static Mig_Info infoArray[MAX_NUM_HOSTS];
  143. static char buf[MAX_MSG_LEN];
  144. static int verbose = 0;
  145. static int debug = 0;
  146. static int local = 0;
  147. static int wallRlogins = 1;
  148. static int consoles = 1;
  149.  
  150. static char alert[0x100];
  151.  
  152. extern int errno;
  153.  
  154. Option optionArray[] = {
  155.     {OPT_TRUE, "l", (Address)&local,
  156.      "Run on local host only."},
  157.     {OPT_TRUE, "v", (Address)&verbose,
  158.      "Print as hosts are accessed."},
  159.     {OPT_TRUE, "d", (Address)&debug,
  160.      "Enable debugging."},
  161.     {OPT_FALSE, "r", (Address)&wallRlogins,
  162.      "Don't write to rlogins (useful if the swap server is down)."},
  163.     {OPT_FALSE, "C", (Address)&consoles,
  164.      "Don't write to consoles (useful just for debugging."},
  165. };
  166.  
  167. /*
  168.  *----------------------------------------------------------------------
  169.  *
  170.  * main --
  171.  *
  172.  *    Prompts the invoker for a message, and then prints the
  173.  *      message to the /dev/syslog of all sprite machines.
  174.  *
  175.  * Results:
  176.  *    Zero exit code if there are no errors.
  177.  *
  178.  * Side effects:
  179.  *    Print a message to everybody's /dev/syslog.
  180.  *
  181.  *----------------------------------------------------------------------
  182.  */
  183.  
  184. void
  185. main(argc, argv)
  186.     int argc;
  187.     char **argv;
  188. {
  189.     register int n;
  190.     register Mig_Info *infoPtr;
  191.     register Host_Entry *hostPtr;
  192.     register char *b;
  193.     register int r;
  194.     register int size;
  195.     register int numRecs;
  196.     int doPrompt;
  197.     int loopIndex;
  198.     int myID;
  199.  
  200.     (void) Opt_Parse(argc, argv, optionArray, Opt_Number(optionArray),
  201.              OPT_ALLOW_CLUSTERING);
  202.  
  203.     FillAlert();
  204.     if ((numRecs = Mig_GetAllInfo(infoArray, MAX_NUM_HOSTS)) <= 0) {
  205.     perror("Error in Mig_GetAllInfo");
  206.     exit(1);
  207.     }
  208.     if ((doPrompt = isatty(0)) != 0) {
  209.     Prompt();
  210.     }
  211.     for (b = buf, size = sizeof(buf); (r = read(0, b, size)) > 0; b += r) {
  212.     if ((size -= r) == 0) {
  213.         (void) fprintf(stderr, "WARNING: max message length exceeded\n");
  214.         break;
  215.     }
  216.     /*
  217.      * stop if a `.' appears at the beginning of a line.
  218.      * This assumes that stdin is line buffered.
  219.      */
  220.     if (*b == '.' && b[-1] == '\n') {
  221.         break;
  222.     }
  223.     if (doPrompt) {
  224.         Prompt();
  225.     }
  226.     }
  227.     size = sizeof(buf) - size;
  228.     if (local) {
  229.     (void) Proc_GetHostIDs(&myID, (int *) NULL);
  230.     }
  231.     for (loopIndex = !consoles; loopIndex <= wallRlogins; loopIndex++) {
  232.     for (n = 0, infoPtr = &infoArray[0]; n < numRecs; ++infoPtr, ++n) {
  233.         if (infoPtr->loadVec.timestamp == 0) {
  234.         continue;
  235.         }
  236.         if (local && infoPtr->hostID != myID) {
  237.         continue;
  238.         }
  239.         if (infoPtr->state == MIG_HOST_DOWN) {
  240.         if (verbose) {
  241.             Down(infoPtr->hostID);
  242.         }
  243.         continue;
  244.         }
  245.         if (infoPtr->loadVec.timestamp - infoPtr->bootTime < 0) {
  246.         if (verbose) {
  247.             Down(infoPtr->hostID);
  248.         }
  249.         continue;
  250.         }
  251.         if ((hostPtr = Host_ByID(infoPtr->hostID)) == NULL) {
  252.         (void) fprintf(stderr, "Error in Host_ByID(%d)\n", infoPtr->hostID);
  253.         continue;
  254.         }
  255.         SendMsg(buf, size, hostPtr->name, loopIndex);
  256.     }
  257.     }
  258.     exit(0);
  259. }   /* main */
  260.  
  261.  
  262. /*
  263.  *----------------------------------------------------------------------
  264.  *
  265.  * Down --
  266.  *
  267.  *      Print a list of all machines that are down.
  268.  *
  269.  * Results:
  270.  *      None.
  271.  * 
  272.  * Side effects:
  273.  *      Prints a list to stdout.
  274.  *  
  275.  *----------------------------------------------------------------------
  276.  */ 
  277.  
  278. static void
  279. Down(n)
  280.     int n;
  281. {
  282.     Host_Entry *hostPtr;
  283.  
  284.     if ((hostPtr = Host_ByID(n)) == NULL) {
  285.     (void) fprintf(stderr, "Error in Host_ByID(%d)\n", n);
  286.     return;
  287.     }
  288.     (void) printf("%s is down\n", hostPtr->name);
  289. }
  290.  
  291.  
  292. /*
  293.  * Set the default timeout, in seconds.
  294.  */
  295. #ifndef TIMEOUT
  296. #define TIMEOUT 10
  297. #endif /* TIMEOUT */
  298. char currentFile[0x400];
  299. int exited;
  300. static jmp_buf    OpenTimeout;
  301.  
  302.  
  303. /*
  304.  *----------------------------------------------------------------------
  305.  *
  306.  * AlarmHandler --
  307.  *
  308.  *    Routine to service a SIGALRM signal.  This routine disables
  309.  *    the alarm (letting the caller reenable it when appropriate).
  310.  *
  311.  * Results:
  312.  *    None.
  313.  *
  314.  * Side effects:
  315.  *    The alarm is disabled, and a warning message is printed. A
  316.  *     global variable is set to indicate that the parent should give up.
  317.  *
  318.  *----------------------------------------------------------------------
  319.  */
  320. static int
  321. AlarmHandler()
  322. {
  323.     exited = 1;
  324.     alarm(0);
  325.     fprintf(stderr, "Warning: couldn't write to %s; removing file.\n",
  326.         currentFile);
  327.     fflush(stderr);
  328.     if (unlink(currentFile) < 0) {
  329.     perror("unlink");
  330.     }
  331.     (void) signal (SIGALRM, SIG_IGN);
  332.     longjmp(OpenTimeout, 1);
  333. }
  334.  
  335. /*
  336.  *----------------------------------------------------------------------
  337.  *
  338.  * SendMsg --
  339.  *
  340.  *      Write the message to a specific host.
  341.  *
  342.  * Results:
  343.  *      None.
  344.  * 
  345.  * Side effects:
  346.  *      Writes the message to the /dev/syslog of the specified host.
  347.  *  
  348.  *----------------------------------------------------------------------
  349.  */ 
  350.  
  351. static void
  352. SendMsg(msg, msize, host, doRlogin)
  353.     char *msg;
  354.     int msize;
  355.     char *host;
  356.     int doRlogin;
  357. {
  358.     int fd;
  359.     int i;
  360.     struct stat statBuf;
  361.     char *s = currentFile;
  362.     int pid;
  363.     
  364.  
  365.     if (!doRlogin) {
  366.     (void) sprintf(s, "/hosts/%s/dev/syslog", host);
  367.     if (debug) {
  368.         printf("would write to %s\n", s);
  369.         return;
  370.     } 
  371.     fd = open(s, O_WRONLY);
  372.     if (fd < 0) {
  373.         perror(s);
  374.         return;
  375.     }
  376.     if (verbose) {
  377.         (void) printf("sending to %s\n", host);
  378.     }
  379.     (void) write(fd, alert, strlen(alert));
  380.     (void) write(fd, msg, msize);
  381.     (void) write(fd, "\7\7\7", 3);
  382.     (void) close(fd);
  383.     } else {
  384.     for (i = 1; i < ULOG_MAX_PORTS; ++i) {
  385.         (void) sprintf(s, "/hosts/%s/%s%d", host, RLOGIN_PDEV_NAME, i);
  386.         if (debug) {
  387.         printf("would write to %s\n", s);
  388.         return;
  389.         } 
  390.         if (stat(s, &statBuf) < 0) {
  391.         continue;
  392.         }
  393.         pid = fork();
  394.         if (pid) {
  395.         union wait status;
  396.         int error;
  397.         int exitCode;
  398.         struct itimerval itimer;
  399.  
  400.         itimer.it_interval.tv_sec = 0;
  401.         itimer.it_interval.tv_usec = 0;
  402.         itimer.it_value.tv_sec = TIMEOUT;
  403.         itimer.it_value.tv_usec = 0;
  404.         (void) signal(SIGALRM, AlarmHandler);
  405.         (void) setitimer(ITIMER_REAL, &itimer, NULL);
  406.  
  407.         exited = 0;
  408.         do {
  409.             if (setjmp(OpenTimeout) != 0) {
  410.             break;
  411.             }
  412.             error = wait(&status);
  413.             if (error == -1) {
  414.             if (errno == EINTR) {
  415.                 /*
  416.                  * This will unfortunately never be reached
  417.                  * until wait can actually return EINTR (not
  418.                  * possible now due to migration interactions
  419.                  * with signals).  Hence the setjmp.
  420.                  */
  421.                 break;
  422.             } else {
  423.                 perror("wait");
  424.                 exited = 1;
  425.             }
  426.             } else if (error == pid) {
  427.             if (status.w_stopval != WSTOPPED) {
  428.                 exited = 1;
  429.             }
  430.             }
  431.         } while (!exited);
  432.         itimer.it_value.tv_sec = 0;
  433.         (void) setitimer(ITIMER_REAL, &itimer, NULL);
  434.         } else {
  435.         /*
  436.          * Child.
  437.          */
  438.         if (verbose) {
  439.             (void) printf("Opening %s.\n", s);
  440.         }
  441.         fd = open(s, O_WRONLY | O_APPEND);
  442.         if (fd < 0) {
  443.             exit(1);
  444.         }
  445.         if (verbose) {
  446.             (void) printf("Writing to %s.\n", s);
  447.         }
  448.         if (write(fd, alert, strlen(alert)) < 0) {
  449.             exit(1);
  450.         }
  451.         (void) write(fd, msg, msize);
  452.         (void) write(fd, "\7\7\7", 3);
  453.         (void) close(fd);
  454.         exit(0);
  455.         } 
  456.         
  457.     }
  458.     }
  459.     return;
  460. }
  461.  
  462.  
  463. /*
  464.  *----------------------------------------------------------------------
  465.  *
  466.  * FillAlert --
  467.  *
  468.  *      Creates the `alert' message that is sent as a prelude
  469.  *      to the main message.
  470.  *
  471.  * Results:
  472.  *      None.
  473.  * 
  474.  * Side effects:
  475.  *      Prints a string into the `alert' buffer.
  476.  *  
  477.  *----------------------------------------------------------------------
  478.  */ 
  479.  
  480. static void
  481. FillAlert()
  482. {
  483.     char *me;
  484.     char hostname[32];
  485.     long clock;
  486.     char *timestamp;
  487. #ifdef notdef
  488.     struct tm *localtime();
  489.     struct tm *localclock;
  490. #endif
  491.     char *ttyname();
  492.  
  493.     me = getpwuid(getuid())->pw_name;
  494.     (void) gethostname(hostname, sizeof(hostname));
  495.     (void) time(&clock);
  496.     timestamp = ctime(&clock);
  497. #ifdef notdef
  498.     localclock = localtime(&clock);
  499.     (void) sprintf(alert,
  500.     "\7\7\7%s broadcast message from %s@@%s at %d:%02d ...\n",
  501.     local ? "Local" : "Network-wide", me, hostname,
  502.            localclock->tm_hour, localclock->tm_min);
  503. #endif
  504.     (void) sprintf(alert,
  505.     "\7\7\7%s broadcast message from %s@@%s at %s ...\n",
  506.     local ? "Local" : "Network-wide", me, hostname, timestamp);
  507.     return;
  508. }
  509.  
  510.  
  511. /*
  512.  *----------------------------------------------------------------------
  513.  *
  514.  * Prompt --
  515.  *
  516.  *      Print a prompt.
  517.  *
  518.  * Results:
  519.  *      None.
  520.  * 
  521.  * Side effects:
  522.  *      Prints a prompt to stdout.
  523.  *  
  524.  *----------------------------------------------------------------------
  525.  */ 
  526.  
  527. static void
  528. Prompt()
  529. {
  530.  
  531.     (void) write(1, "> ", 2);
  532.     return;
  533. }
  534.  
  535. @
  536.  
  537.  
  538. 1.12
  539. log
  540. @time out and remove bad rlogin file
  541. @
  542. text
  543. @d18 1
  544. a18 1
  545. static char rcsid[] = "$Header: /sprite/src/cmds/wall/RCS/wall.c,v 1.11 90/04/30 10:59:00 douglis Exp Locker: douglis $";
  546. d36 1
  547. d38 1
  548. d300 2
  549. a301 2
  550.     for (i = 1; i < 10; ++i) {
  551.         (void) sprintf(s, "/hosts/%s/rlogin%d", host, i);
  552. @
  553.  
  554.  
  555. 1.11
  556. log
  557. @cleaned up a bit.
  558. @
  559. text
  560. @d18 1
  561. a18 1
  562. static char rcsid[] = "$Header: /sprite/src/cmds/wall/RCS/wall.c,v 1.10 89/12/11 13:09:32 douglis Exp Locker: douglis $";
  563. d32 5
  564. d45 4
  565. a48 4
  566. static void sendMsg(char *msg, int msize, char *host, int doRlogin);
  567. static void fillAlert(void);
  568. static void down(int n);
  569. static void prompt(void);
  570. d50 4
  571. a53 4
  572. static void sendMsg();
  573. static void fillAlert();
  574. static void down();
  575. static void prompt();
  576. d62 1
  577. d66 2
  578. d77 2
  579. d117 1
  580. a117 1
  581.     fillAlert();
  582. d123 1
  583. a123 1
  584.     prompt();
  585. d138 1
  586. a138 1
  587.         prompt();
  588. d145 1
  589. a145 1
  590.     for (loopIndex = 0; loopIndex <= wallRlogins; loopIndex++) {
  591. d155 1
  592. a155 1
  593.             down(infoPtr->hostID);
  594. d161 1
  595. a161 1
  596.             down(infoPtr->hostID);
  597. d169 1
  598. a169 1
  599.         sendMsg(buf, size, hostPtr->name, loopIndex);
  600. d179 1
  601. a179 1
  602.  * down --
  603. d193 1
  604. a193 1
  605. down(n)
  606. d207 43
  607. d252 1
  608. a252 1
  609.  * sendMsg --
  610. d266 1
  611. a266 1
  612. sendMsg(msg, msize, host, doRlogin)
  613. a272 1
  614.     char s[0x400];
  615. d274 4
  616. d304 1
  617. a304 1
  618.         if ((fd = open(s, O_WRONLY | O_APPEND)) < 0) {
  619. d307 64
  620. a370 6
  621.         if (write(fd, alert, strlen(alert)) < 0) {
  622.         continue;
  623.         }
  624.         (void) write(fd, msg, msize);
  625.         (void) write(fd, "\7\7\7", 3);
  626.         (void) close(fd);
  627. d380 1
  628. a380 1
  629.  * fillAlert --
  630. d395 1
  631. a395 1
  632. fillAlert()
  633. d428 1
  634. a428 1
  635.  * doPrompt --
  636. d442 1
  637. a442 1
  638. prompt()
  639. @
  640.  
  641.  
  642. 1.10
  643. log
  644. @use ctime to generate datestamp so we print date as well as time.
  645. @
  646. text
  647. @d18 1
  648. a18 1
  649. static char rcsid[] = "$Header: /sprite/src/cmds/wall/RCS/wall.c,v 1.9 89/11/27 14:27:10 douglis Exp Locker: douglis $";
  650. a52 1
  651. static struct timeval currentTime;
  652. a106 4
  653.     if (gettimeofday(¤tTime, (struct timezone *) NULL) < 0) {
  654.     perror("gettimeofday");
  655.     exit(1);
  656.     }
  657. d112 1
  658. a112 1
  659.     if ((doPrompt = isatty(0)) != 0)
  660. d114 1
  661. d124 1
  662. a124 1
  663.     if (*b == '.' && b[-1] == '\n')
  664. d126 2
  665. a127 1
  666.     if (doPrompt)
  667. d129 1
  668. d137 1
  669. a137 4
  670.         if (infoPtr ->timestamp == 0)
  671.         continue;
  672.         if (infoPtr->hostID != n) {
  673.         (void) fprintf(stderr, "ListHosts: bad hostID for entry %d\n", n);
  674. d143 4
  675. a146 3
  676.         if (currentTime.tv_sec - infoPtr->timestamp > TIME_OUT) {
  677.         if (verbose)
  678.             down(n);
  679. d149 8
  680. a156 7
  681.         if (infoPtr->timestamp - infoPtr->bootTime < 0) {
  682.         if (verbose)
  683.             down(n);
  684.         continue;
  685.         }
  686.         if ((hostPtr = Host_ByID(n)) == NULL) {
  687.         (void) fprintf(stderr, "Error in Host_ByID(%d)\n", n);
  688. d234 1
  689. a234 1
  690.     if (verbose)
  691. d236 1
  692. d300 3
  693. a302 2
  694.     "\7\7\7Broadcast message from %s@@%s at %d:%02d ...\n",
  695.     me, hostname, localclock->tm_hour, localclock->tm_min);
  696. d305 2
  697. a306 2
  698.     "\7\7\7Broadcast message from %s@@%s at %s ...\n",
  699.     me, hostname, timestamp);
  700. @
  701.  
  702.  
  703. 1.9
  704. log
  705. @added -r (no rlogins) option
  706. @
  707. text
  708. @d18 1
  709. a18 1
  710. static char rcsid[] = "$Header: /sprite/src/cmds/wall/RCS/wall.c,v 1.8 89/11/21 15:56:21 douglis Exp Locker: douglis $";
  711. d288 2
  712. d292 1
  713. d298 2
  714. d304 4
  715. @
  716.  
  717.  
  718. 1.8
  719. log
  720. @added -l option
  721. @
  722. text
  723. @d18 1
  724. a18 1
  725. static char rcsid[] = "$Header: /sprite/src/cmds/wall/RCS/wall.c,v 1.7 89/09/29 11:24:14 douglis Exp Locker: douglis $";
  726. d57 1
  727. d68 2
  728. d102 1
  729. a102 1
  730.     int doRlogin;
  731. d137 1
  732. a137 1
  733.     for (doRlogin = 0; doRlogin <= 1; doRlogin++) {
  734. d162 1
  735. a162 1
  736.         sendMsg(buf, size, hostPtr->name, doRlogin);
  737. d246 4
  738. @
  739.  
  740.  
  741. 1.7
  742. log
  743. @fixed prototype problem with last change
  744. @
  745. text
  746. @d5 1
  747. a5 1
  748.  * each machine.
  749. d18 1
  750. a18 1
  751. static char rcsid[] = "$Header: /a/newcmds/wall/RCS/wall.c,v 1.6 89/09/29 11:22:18 douglis Exp Locker: douglis $";
  752. d31 1
  753. d56 2
  754. d60 8
  755. d100 1
  756. a100 5
  757.  
  758.     switch (argc) {
  759.  
  760.     case 1:
  761.         break;
  762. d102 2
  763. a103 10
  764.     case 2:
  765.         if (strncmp(argv[1], "-v", 2) == 0) {
  766.         verbose = 1;
  767.         break;
  768.     }
  769.         if (strncmp(argv[1], "-d", 2) == 0) {
  770.         debug = 1;
  771.         break;
  772.     }
  773.     /* FALLTHROUGH*/
  774. a104 4
  775.     default:
  776.         (void) fprintf(stderr, "usage: wall [-{v|d}]\n");
  777.     exit(1);
  778.     }
  779. d131 3
  780. d142 3
  781. d307 1
  782. a307 1
  783.  *      Prints a promp to stdout.
  784. @
  785.  
  786.  
  787. 1.6
  788. log
  789. @do rlogins only after syslogs
  790. @
  791. text
  792. @d18 1
  793. a18 1
  794. static char rcsid[] = "$Header: /a/newcmds/wall/RCS/wall.c,v 1.5 89/09/29 11:14:47 douglis Exp Locker: douglis $";
  795. d39 1
  796. a39 1
  797. static void sendMsg(char *msg, int msize, char *host);
  798. @
  799.  
  800.  
  801. 1.5
  802. log
  803. @open in append mode.  debug flag.
  804. @
  805. text
  806. @d18 1
  807. a18 1
  808. static char rcsid[] = "$Header: /a/newcmds/wall/RCS/wall.c,v 1.4 89/08/28 15:32:58 douglis Exp Locker: douglis $";
  809. d88 1
  810. d136 23
  811. a158 20
  812.     for (n = 0, infoPtr = &infoArray[0]; n < numRecs; ++infoPtr, ++n) {
  813.     if (infoPtr ->timestamp == 0)
  814.         continue;
  815.     if (infoPtr->hostID != n) {
  816.         (void) fprintf(stderr, "ListHosts: bad hostID for entry %d\n", n);
  817.         continue;
  818.     }
  819.     if (currentTime.tv_sec - infoPtr->timestamp > TIME_OUT) {
  820.         if (verbose)
  821.         down(n);
  822.         continue;
  823.     }
  824.     if (infoPtr->timestamp - infoPtr->bootTime < 0) {
  825.         if (verbose)
  826.         down(n);
  827.         continue;
  828.     }
  829.     if ((hostPtr = Host_ByID(n)) == NULL) {
  830.         (void) fprintf(stderr, "Error in Host_ByID(%d)\n", n);
  831.         continue;
  832. a159 1
  833.     sendMsg(buf, size, hostPtr->name);
  834. d212 1
  835. a212 1
  836. sendMsg(msg, msize, host)
  837. d216 1
  838. d222 10
  839. a231 20
  840.     (void) sprintf(s, "/hosts/%s/dev/syslog", host);
  841.     if (debug) {
  842.     printf("would write to %s\n", s);
  843.     return;
  844.     } 
  845.     fd = open(s, O_WRONLY);
  846.     if (fd < 0) {
  847.     perror(s);
  848.     return;
  849.     }
  850.     if (verbose)
  851.     (void) printf("sending to %s\n", host);
  852.     (void) write(fd, alert, strlen(alert));
  853.     (void) write(fd, msg, msize);
  854.     (void) write(fd, "\7\7\7", 3);
  855.     (void) close(fd);
  856.     for (i = 1; i < 10; ++i) {
  857.     (void) sprintf(s, "/hosts/%s/rlogin%d", host, i);
  858.     if ((fd = open(s, O_WRONLY | O_APPEND)) < 0) {
  859.         continue;
  860. d233 3
  861. a235 3
  862.     if (write(fd, alert, strlen(alert)) < 0) {
  863.         continue;
  864.     }
  865. d239 13
  866. @
  867.  
  868.  
  869. 1.4
  870. log
  871. @got rid of "on $TTY" because ttyname is brain-damaged and it's not 
  872. needed anyway.
  873. @
  874. text
  875. @d18 1
  876. a18 1
  877. static char rcsid[] = "$Header: /a/newcmds/wall/RCS/wall.c,v 1.3 89/06/24 18:31:26 rab Exp Locker: douglis $";
  878. d53 2
  879. a54 1
  880. static int verbose;
  881. d99 4
  882. d106 1
  883. a106 1
  884.         (void) fprintf(stderr, "usage: wall [-v]\n");
  885. d219 6
  886. a224 1
  887.     if ((fd = open(s, O_WRONLY)) < 0) {
  888. d233 1
  889. a233 1
  890. #if 0
  891. d236 1
  892. a236 1
  893.     if ((fd = open(s, O_WRONLY)) < 0) {
  894. d244 1
  895. a245 1
  896. #endif
  897. d283 1
  898. a283 1
  899.     me, hostname, mytty, localclock->tm_hour, localclock->tm_min);
  900. @
  901.  
  902.  
  903. 1.3
  904. log
  905. @Added `.' for end of input.
  906. @
  907. text
  908. @d18 1
  909. a18 1
  910. static char rcsid[] = "$Header: /a/newcmds/wall/RCS/wall.c,v 1.2 89/03/12 20:47:41 rab Exp Locker: rab $";
  911. a261 1
  912.     char *mytty;
  913. a268 4
  914.     if ((mytty = ttyname(2)) == NULL) {
  915.     perror("ttyname");
  916.     exit(1);
  917.     }
  918. d272 1
  919. a272 1
  920.     "\7\7\7Broadcast message from %s@@%s on %s at %d:%02d ...\n",
  921. @
  922.  
  923.  
  924. 1.2
  925. log
  926. @*** empty log message ***
  927. @
  928. text
  929. @d18 1
  930. a18 1
  931. static char rcsid[] = "$Header$";
  932. d38 6
  933. d48 1
  934. d120 6
  935. d153 2
  936. a154 1
  937. }
  938. d211 1
  939. d223 14
  940. d245 1
  941. a245 1
  942.  *      Creates the `alert' message that is send as a prelude
  943. d279 1
  944. d304 1
  945. @
  946.  
  947.  
  948. 1.1
  949. log
  950. @Initial revision
  951. @
  952. text
  953. @d1 1
  954. a1 1
  955. /*
  956. d6 9
  957. d18 2
  958. a19 2
  959. static char rcsid[] = "@@(#)wall.c";
  960. #endif /* !lint */
  961. a31 1
  962. int verbose;
  963. d41 1
  964. d46 1
  965. a46 1
  966.  
  967. d49 18
  968. d79 1
  969. d106 2
  970. d113 2
  971. d116 1
  972. d142 17
  973. d169 1
  974. a169 1
  975.     printf("%s is down\n", hostPtr->name);
  976. d172 17
  977. d204 1
  978. a204 1
  979.     printf("sending to %s\n", host);
  980. d210 18
  981. d250 24
  982. @
  983.